﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WPFExcelReport.Controls"
    
    xmlns:r="clr-namespace:WPFExcelReport.Controls.TreeListViewControl"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic">
    
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/WPFExcelReport.Controls;Component/Themes/Shared.xaml" />
        <ResourceDictionary Source="pack://application:,,,/WPFExcelReport.Controls;Component/TimelineItemPresenterView.xaml" />
        <ResourceDictionary Source="pack://application:,,,/WPFExcelReport.Controls;Component/TimelineControlView.xaml" />
        <ResourceDictionary Source="pack://application:,,,/WPFExcelReport.Controls;Component/ConnectionsPresenterView.xaml" />
        <ResourceDictionary Source="pack://application:,,,/WPFExcelReport.Controls;Component/ConnectionView.xaml" />
        <ResourceDictionary Source="pack://application:,,,/WPFExcelReport.Controls;Component/TimelineRulerControlView.xaml" />
    </ResourceDictionary.MergedDictionaries>
    
    
    <!-- TreeListView Resource -->

    <r:LevelToIndentConverter x:Key="LevelToIndentConverter"/>

    <Style TargetType="{x:Type r:TreeListViewItem}">

        <Setter Property="Panel.Background">
            <Setter.Value>
                <SolidColorBrush>#00FFFFFF</SolidColorBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.HorizontalContentAlignment">
            <Setter.Value>
                <Binding Path="HorizontalContentAlignment" RelativeSource="{RelativeSource AncestorLevel=1, Mode=FindAncestor, AncestorType=ItemsControl}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Control.VerticalContentAlignment">
            <Setter.Value>
                <Binding Path="VerticalContentAlignment" RelativeSource="{RelativeSource AncestorLevel=1, Mode=FindAncestor, AncestorType=ItemsControl}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Padding">
            <Setter.Value>
                <Thickness>1,0,0,0</Thickness>
            </Setter.Value>
        </Setter>
        <Setter Property="TextElement.Foreground">
            <Setter.Value>
                <DynamicResource ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
            </Setter.Value>
        </Setter>
        <Setter Property="FrameworkElement.FocusVisualStyle">
            <Setter.Value>
                <Style TargetType="IFrameworkInputElement">
                    <Style.Resources>
                        <ResourceDictionary />
                    </Style.Resources>
                    <Setter Property="Control.Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Rectangle />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="r:TreeListViewItem">
                    <StackPanel>
                        <Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Bd" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True" Padding="{TemplateBinding Control.Padding}">
                            <r:TreeGridViewRowPresenter x:Name="PART_Header"
                                FirstColumnIndent="{Binding Level,Converter={StaticResource LevelToIndentConverter},RelativeSource={RelativeSource AncestorType={x:Type r:TreeListViewItem}},ConverterParameter=19}"
                                Content="{TemplateBinding Header}" 
                                Columns="{Binding Path=Columns,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListView}}}">
                                <r:TreeGridViewRowPresenter.Expander>
                                    <Grid>
                                        <ToggleButton Width="19" Height="16" ClickMode="Press" Name="Expander"
                                                  IsChecked="{Binding Path=IsExpanded,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListViewItem}}}">
                                            <ToggleButton.Style>
                                                <Style TargetType="ToggleButton">
                                                    <Style.Resources>
                                                        <ResourceDictionary />
                                                    </Style.Resources>
                                                    <Setter Property="UIElement.Focusable">
                                                        <Setter.Value>
                                                            <s:Boolean>False</s:Boolean>
                                                        </Setter.Value>
                                                    </Setter>
                                                    <Setter Property="FrameworkElement.Width">
                                                        <Setter.Value>
                                                            <s:Double>19</s:Double>
                                                        </Setter.Value>
                                                    </Setter>
                                                    <Setter Property="FrameworkElement.Height">
                                                        <Setter.Value>
                                                            <s:Double>13</s:Double>
                                                        </Setter.Value>
                                                    </Setter>
                                                    <Setter Property="Control.Template">
                                                        <Setter.Value>
                                                            <ControlTemplate TargetType="ToggleButton">
                                                                <Border Height="13" Width="19" Background="#00FFFFFF">
                                                                    <Border Height="9" BorderBrush="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" Width="9" BorderThickness="1,1,1,1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" SnapsToDevicePixels="True">
                                                                        <Path Margin="1,1,1,1" Data="M0,2L0,3 2,3 2,5 3,5 3,3 5,3 5,2 3,2 3,0 2,0 2,2z" Fill="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" Name="ExpandPath" />
                                                                    </Border>
                                                                </Border>
                                                                <ControlTemplate.Triggers>
                                                                    <Trigger Property="ToggleButton.IsChecked">
                                                                        <Setter Property="Path.Data" TargetName="ExpandPath">
                                                                            <Setter.Value>
                                                                                <StreamGeometry>M0,2L0,3 5,3 5,2z</StreamGeometry>
                                                                            </Setter.Value>
                                                                        </Setter>
                                                                        <Trigger.Value>
                                                                            <s:Boolean>True</s:Boolean>
                                                                        </Trigger.Value>
                                                                    </Trigger>
                                                                </ControlTemplate.Triggers>
                                                            </ControlTemplate>
                                                        </Setter.Value>
                                                    </Setter>
                                                </Style>
                                            </ToggleButton.Style>
                                        </ToggleButton>
                                    </Grid>
                                </r:TreeGridViewRowPresenter.Expander>
                            </r:TreeGridViewRowPresenter>
                        </Border>

                        <ItemsPresenter Name="ItemsHost" />
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TreeViewItem.IsExpanded">
                            <Setter Property="UIElement.Visibility" TargetName="ItemsHost" Value="{x:Static Visibility.Collapsed}" />
                            <Trigger.Value>
                                <s:Boolean>False</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                        <Trigger Property="ItemsControl.HasItems">
                            <Setter Property="UIElement.Visibility" TargetName="Expander" Value="{x:Static Visibility.Hidden}" />
                            <Trigger.Value>
                                <s:Boolean>False</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                        <Trigger Property="TreeViewItem.IsSelected">
                            <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                            <Setter Property="TextElement.Foreground">
                                <Setter.Value>
                                    <DynamicResource ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" />
                                </Setter.Value>
                            </Setter>
                            <Trigger.Value>
                                <s:Boolean>True</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="TreeViewItem.IsSelected">
                                    <Condition.Value>
                                        <s:Boolean>True</s:Boolean>
                                    </Condition.Value>
                                </Condition>
                                <Condition Property="TreeViewItem.IsSelectionActive">
                                    <Condition.Value>
                                        <s:Boolean>False</s:Boolean>
                                    </Condition.Value>
                                </Condition>
                            </MultiTrigger.Conditions>
                            <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                            <Setter Property="TextElement.Foreground">
                                <Setter.Value>
                                    <DynamicResource ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
                                </Setter.Value>
                            </Setter>
                        </MultiTrigger>
                        <Trigger Property="UIElement.IsEnabled">
                            <Setter Property="TextElement.Foreground">
                                <Setter.Value>
                                    <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                                </Setter.Value>
                            </Setter>
                            <Trigger.Value>
                                <s:Boolean>False</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

    <Style x:Key="scroll">
        <Setter Property="UIElement.Focusable">
            <Setter.Value>
                <s:Boolean>False</s:Boolean>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid Background="{TemplateBinding Background}"
                SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <DockPanel Margin="{TemplateBinding Padding}">
                            <ScrollViewer DockPanel.Dock="Top"
                            HorizontalScrollBarVisibility="Hidden"
                            VerticalScrollBarVisibility="Hidden"
                            Focusable="false">
                                <GridViewHeaderRowPresenter Columns="{Binding Path=Columns,RelativeSource={RelativeSource AncestorType={x:Type r:TreeListView}}}"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </ScrollViewer>
                            <ScrollContentPresenter Name="PART_ScrollContentPresenter"
                                      KeyboardNavigation.DirectionalNavigation="Local"
                                      Content="{TemplateBinding Content}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                      CanContentScroll="{TemplateBinding CanContentScroll}"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </DockPanel>
                        <ScrollBar Name="PART_HorizontalScrollBar"
                       Orientation="Horizontal"
                       Grid.Row="1"
                       Minimum="0.0"
                       Maximum="{TemplateBinding ScrollableWidth}"
                       ViewportSize="{TemplateBinding ViewportWidth}"
                       Value="{Binding Path=HorizontalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                       Cursor="Arrow"/>
                        <ScrollBar Name="PART_VerticalScrollBar"
                       Orientation="Vertical"
                       Grid.Column="1"
                       Minimum="0.0"
                       Maximum="{TemplateBinding ScrollableHeight}"
                       ViewportSize="{TemplateBinding ViewportHeight}"
                       Value="{Binding Path=VerticalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                       Cursor="Arrow"/>
                        <DockPanel Grid.Column="1"
                       Grid.Row="1"
                       Background="{Binding Path=Background,ElementName=PART_VerticalScrollBar}"
                       LastChildFill="false">
                            <Rectangle DockPanel.Dock="Left"
                         Width="1"
                         Fill="White"
                         Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                            <Rectangle DockPanel.Dock="Top"
                         Height="1"
                         Fill="White"
                         Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                        </DockPanel>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type r:TreeListView}">
        <Setter Property="Panel.Background">
            <Setter.Value>
                <DynamicResource ResourceKey="{x:Static SystemColors.WindowBrushKey}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Border.BorderBrush">
            <Setter.Value>
                <SolidColorBrush>#00FFFFFF</SolidColorBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Border.BorderThickness">
            <Setter.Value>
                <Thickness>2,2,2,2</Thickness>
            </Setter.Value>
        </Setter>
        <Setter Property="TextElement.Foreground">
            <Setter.Value>
                <DynamicResource ResourceKey="{x:Static SystemColors.WindowTextBrushKey}" />
            </Setter.Value>
        </Setter>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility">
            <Setter.Value>
                <x:Static Member="ScrollBarVisibility.Auto" />
            </Setter.Value>
        </Setter>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility">
            <Setter.Value>
                <x:Static Member="ScrollBarVisibility.Auto" />
            </Setter.Value>
        </Setter>
        <Setter Property="ScrollViewer.CanContentScroll">
            <Setter.Value>
                <s:Boolean>True</s:Boolean>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Template">
            <Setter.Value>

                <ControlTemplate TargetType="r:TreeListView">
                    <mwt:ClassicBorderDecorator BorderBrush="{TemplateBinding Border.BorderBrush}" BorderStyle="Sunken" 
                                                BorderThickness="{TemplateBinding Border.BorderThickness}" 
                                                Name="Bd" 
                                                Background="{TemplateBinding Panel.Background}" 
                                                SnapsToDevicePixels="True">

                        <ScrollViewer Style="{StaticResource scroll}" Background="{TemplateBinding Background}"
                          Focusable="false"
                          CanContentScroll="false"
                          HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                          VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                          Padding="{TemplateBinding Padding}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                        </ScrollViewer>

                    </mwt:ClassicBorderDecorator>

                    <ControlTemplate.Triggers>
                        <Trigger Property="UIElement.IsEnabled">
                            <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                            <Trigger.Value>
                                <s:Boolean>False</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

    <!-- End of TreeListView Resources -->
</ResourceDictionary>
